
#!/bin/perl
use strict;
use warnings;
use File::Basename;

print "Avaiable sessions:\n";
my @all_sessions = glob("~/gvim_sessions/*/Session.vim");
my $session_count = 0;
foreach (@all_sessions){
  printf "  %2s) %s\n", ++$session_count, basename(dirname $_);
}

print "Your choice: ";
chomp(my $choice = <>);
if(($choice =~ /^\s*\d+\s*$/) && ($choice <= $session_count) && ($choice >= 1)){
  print "Starting session $all_sessions[$choice-1]\n"; 
  system("gvim -S $all_sessions[$choice-1] &");
  print "Done^_^\n";
}else{
  print "Wrong input!\n";
  exit;
}



